package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chuji.crmcj.R;
import com.chuji.crmcj.act.DisposableAct;
import com.chuji.crmcj.bean.DisposableInfo;

/**
 * Created by w.pitt on 2016/1/22.
 * Todo  缺参数  投诉时间
 * Todo
 */
public class DisposableAdapter extends BaseAdapter {
    private DisposableInfo disposableInfo;
    private Context mContext;
    private ViewHolder holder;

    public DisposableAdapter(DisposableAct disposableAct, DisposableInfo disposableInfo) {
        this.mContext = disposableAct;
        this.disposableInfo = disposableInfo;
    }

    @Override
    public int getCount() {
        return disposableInfo.getApiParamObj().size() == 0 ? 0 : disposableInfo.getCount();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            holder = new ViewHolder();
            view = view.inflate(mContext, R.layout.item_saler, null);
            holder.mIvSalerIcon = (ImageView) view.findViewById(R.id.iv_saler_icon);
            holder.mTvSalerName = (TextView) view.findViewById(R.id.tv_sale_name);
            holder.mTvReceptionNumber = (TextView) view.findViewById(R.id.tv_reception_number);
            holder.mTvTime = (TextView) view.findViewById(R.id.tv_time);
            holder.mTvIntoTime = (TextView) view.findViewById(R.id.tv_into_time);
            holder.mTvGoOutTime = (TextView) view.findViewById(R.id.tv_goout_time);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.mTvReceptionNumber.setText("接待" + disposableInfo.getApiParamObj().get(i).getCustomerCount() + "人");
        holder.mTvSalerName.setText(disposableInfo.getApiParamObj().get(i).getRealName());
        holder.mTvIntoTime.setText(disposableInfo.getApiParamObj().get(i).getEnterTime());
        holder.mTvGoOutTime.setText(disposableInfo.getApiParamObj().get(i).getExitTime());
        holder.mTvTime.setText(disposableInfo.getApiParamObj().get(i).getTaskCreateTime());
        Glide.with(mContext).load(disposableInfo.getApiParamObj().get(i).getAvatar()).into(holder.mIvSalerIcon);

        return view;
    }

    private static class ViewHolder {
        private ImageView mIvSalerIcon;
        private TextView mTvSalerName;
        private TextView mTvReceptionNumber;
        private TextView mTvTime;
        private TextView mTvIntoTime;
        private TextView mTvGoOutTime;
    }
}
